
"""Bootstrap for running a Django app under Google App Engine.

The site-specific code is all in other files: settings.py, urls.py,
models.py, views.py.  And in fact, only 'settings' is referenced here
directly -- everything else is controlled from there.

"""

# Standard Python imports.
import os
import sys
import logging
import __builtin__

# Google App Hosting imports.
from google.appengine.ext.webapp import util



# Force Django to reload its settings.
from django.conf import settings
settings._target = None

# Must set this env var *before* importing any part of Django.
os.environ['DJANGO_SETTINGS_MODULE'] = 'conf.settings'

import django.core.handlers.wsgi
#import django.core.signals
import django.db
import django.dispatch.dispatcher


def log_exception(*args, **kwds):  
    logging.exception('Exception in request:')
# Log errors.
django.dispatch.dispatcher.connect(                                      
                                   log_exception, django.core.signals.got_request_exception)
# Unregister the rollback event handler.
django.dispatch.dispatcher.disconnect(    
                                      django.db._rollback_on_exception,    
                                      django.core.signals.got_request_exception)

#vinh import pickle
#vinh sys.modules['cPickle'] = pickle

# Enable info logging by the app (this is separate from appserver's
# logging).
logging.getLogger().setLevel(logging.INFO)



def main():
  # Create a Django application for WSGI.
  
  application = django.core.handlers.wsgi.WSGIHandler()
  # Run the WSGI CGI handler with that application.
  
  util.run_wsgi_app(application)
 


if __name__ == '__main__':
  main()
